﻿using System;
using System.Linq;
using TravelAgency.DAL;

namespace TravelAgency.AspNet.Agents
{
    public partial class DeleteEmptyTrip : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void LinkButtonCancel_Click(object sender, EventArgs e)
        {
            this.Response.Redirect("/Agents/ManageTrips.aspx");
        }

        protected void LinkButtonDelete_Click(object sender, EventArgs e)
        {
            string tripIdString = this.Request.QueryString["tripId"];
            int tripId = int.Parse(tripIdString);

            TravelAgencyDAO dao = new TravelAgencyDAO();
            using (dao)
            {
                try
                {
                    dao.DeleteTripByTripId(tripId);
                    dao.SaveChanges();
                    this.Response.Redirect("~/Agents/TripDeleted.aspx");
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }            
        }
    }
}